﻿using EFCore读写分离.DAL;
using EFCore读写分离.IService;
using EFCore读写分离.Models;
using EFCore读写分离.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace EFCore读写分离
{
    public class Program
    {
        static void Main(string[] args)
        {
            var connConfigs = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .Build()
                .GetSection("ConnectionStrings");
            DbConnectionOptions dbConnectionOptions = connConfigs.Get<DbConnectionOptions>();
            var serviceProvider = new ServiceCollection()
                .AddOptions()
                .AddLogging(builder => builder.AddConsole())
                .AddSingleton(dbConnectionOptions)
                .AddSingleton<SlaveRoundRobin>()
                .AddDbContext<DbApplicationContext>()
                .AddSingleton<IBaseService,BaseService>()
                .AddSingleton<IDataUserService,DataUserService>()
                .BuildServiceProvider();

            DbConnectionOptions dbConnectionOptions2 = serviceProvider.GetRequiredService<DbConnectionOptions>(); 
            IDataUserService _userService = serviceProvider.GetRequiredService<IDataUserService>();
           
            List<DataUser> dataUsers = _userService.SelectList<DataUser>(null);
            List<DataUser> dataUsers1 = _userService.SelectList<DataUser>(u => u.Age > 18);
            Common.PageResult<DataUser> pageResult = _userService.SelectPage<DataUser,int>(u => u.Age > 18, 1, 12, u => u.Id);

        }
    }
}
